// Copyright 2024 Tvux
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package _392

// isSubsequence
// 判断过的部分进行删除，最后判断s的长度是否为0
// 比如：
// "abc"
// "ahbgdc"
// 第一个字符相等，所以s="bc",t="hbgdc"
// 第一个字符不相等，所以t="bgdc"
// 第一个字符相等，所以s="c",t="gdc"
// ... 以此类推
// 最后，len(s)==0，return true
// 时间复杂度：O(n)
func isSubsequence(s string, t string) bool {
	for len(s) > 0 && len(t) > 0 {
		if s[0] == t[0] {
			s = s[1:]
		}
		t = t[1:]
	}
	return len(s) == 0
}

// isSubsequence
// O(n^2)
//func isSubsequence(s string, t string) bool {
//	j := 0
//	for i := 0; i < len(s); i++ {
//		flag := false // 标记是否因为有相等字符才break
//		for ; j < len(t); j++ {
//			if s[i] == t[j] {
//				flag = true
//				break
//			}
//		}
//		if !flag {
//			return false
//		}
//		j++ // 更新下一次判断字符的起始位置
//	}
//	return true
//}
